package com.dashu.device.service;

import com.dashu.base.utils.CopyUtil;
import com.dashu.device.dto.attendance.AttendanceRuleDTO;
import com.dashu.device.model.AttendanceDate;
import com.dashu.device.model.AttendancekRule;
import com.dashu.device.model.QAttendancekRule;
import com.querydsl.core.BooleanBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class AttendanceRuleService extends DataService {


    @Autowired
    private CompanyPersonalService companyPersonalService;

    @Autowired
    private AttendanceGroupService attendanceGroupService;
    @Autowired
    private AttendanceDateService attendanceDateService;


    public AttendanceRuleDTO findByAttendancekRuleId(long attendancekRuleId) {
        QAttendancekRule qAttendancekRule = QAttendancekRule.attendancekRule;
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        booleanBuilder.and(qAttendancekRule.id.eq(attendancekRuleId));
        AttendancekRule attendancekRule =
                queryFactory
                        .select(qAttendancekRule)
                        .from(qAttendancekRule)
                        .where(booleanBuilder.getValue())
                        .fetchOne();

        List<AttendanceDate> attendanceDateDTOList = attendanceDateService.findAttendanceGroup(attendancekRuleId);
//        List<AttendanceGroupDTO> attendanceGroupDTOList = attendanceGroupService.findAttendanceGroup(attendancekRuleId);
        AttendanceRuleDTO attendanceRuleDTO = CopyUtil.copyEnty(attendancekRule, AttendanceRuleDTO.class);
        if (attendanceDateDTOList.size() > 0)
            attendanceRuleDTO.setAttendancekDate(attendanceDateDTOList);
//        attendanceRuleDTO.setAttendancekGroup(attendanceGroupDTOList);
        return attendanceRuleDTO;

    }

}
